<?php
/**
 * Created by PhpStrom
 * User: 郭碧云
 * Date: 2021/7/12 16:28
 * Desc:
 */

namespace App\Models;


use Illuminate\Database\Eloquent\SoftDeletes;

class Question extends BaseModel
{
    use SoftDeletes;
    protected $table="question";
    protected $fillable=["type_id","question","level","creator","tag_id","site_id","org_id","org_code","version_id","category_id","category_path"];
    protected $declares = [
        "id"=>["id","="],
        "type_id"=>["type_id","="],
        "level"=>["level","="],
        "creator" => ["creator", "="],
        "tag_id" => ["tag_id", "="],
        "org_id" => ["org_id", "="],
        "version_id" => ["version_id", "="]
    ];

    protected $with = ['type:id,name,choice_type','user:id,name,real_name','org:id,name','tag:id,name','version:id,version','content','category:id,name,path'];

    //关联题型
    public function type(){
        return $this->belongsTo("App\Models\QuestionType","type_id","id");
    }
    //关联科目
    public function category(){
        return $this->belongsTo("App\Models\Category","category_id","id");
    }
    //关联用户表
    public function user(){
        return $this->belongsTo("App\Models\Admin\AdminUser","creator","id");
    }
    //关联组织机构
    public function org(){
        return $this->belongsTo("App\Models\Admin\Org","org_id","id");
    }
    //关联标签
    public function tag(){
        return $this->belongsTo("App\Models\Tag","tag_id","id");
    }
    //关联版本
    public function version(){
        return $this->belongsTo("App\Models\QuestionVersion","version_id","id");
    }

    //关联试题内容及答案
    public function content(){
        return $this->hasOne("App\Models\QuestionContent","question_id","id");
    }
}
